function create_obj() {
	
    browser = navigator.appName;
    if (browser == "Microsoft Internet Explorer") {
        obj = new ActiveXObject("Microsoft.XMLHTTP");
    } else {
        obj = new XMLHttpRequest();
    }
    return obj;
}

var http = create_obj();
function kiemtra_dangphim()
{
	tenphim = encodeURI(document.getElementById("txttenphim").value);
    thoiluong = encodeURI(document.getElementById("txtthoiluong").value);
	nhasx=document.fthemphim.txtnsx.value;
	daodien=document.fthemphim.txtdaodien.value;
	loaiphim=document.fthemphim.txtloaiphim.value;
	quocgia=document.fthemphim.txtquocgia.value;
	chatluong=document.fthemphim.txtchatluong.value;
	chuyenngu=document.fthemphim.txtchuyenngu.value;
	namsx=encodeURI(document.getElementById("txtnamsx").value);
	ngaydang=encodeURI(document.getElementById("txtngaydang").value);
	ngaydangtm=encodeURI(document.getElementById("txtngaydangtm").value);
    gioithieu=encodeURIComponent(document.getElementById("txtgioithieu").value);
	
	theloai=$("[name='txttheloai']:checked").length; 
	num_cb=$("[name='txttheloai']").length;
	if(theloai==0){
		theloai="";
	}
	else if(theloai==1)
	{
		for(i=1;i<=num_cb;i++)
			if($('#txttheloai'+i).is(':checked'))
			{
				theloai=document.getElementById("txttheloai"+i).value;
				break;
			}
	}
	else
	{
		var theloai = new Array();
		k=0;
		for(i=1;i<=num_cb;i++)
		{
			if($('#txttheloai'+i).is(':checked'))
			{
				
				theloai[k]=document.getElementById("txttheloai"+i).value;
				k++;
			}
		}
	}
	
	
	dienvien=$("[name='txtdienvien']:checked").length; 
	num_dv=$("[name='txtdienvien']").length;
	if(dienvien==0){
		dienvien="";
	}
	else if(dienvien==1)
	{
		for(i=1;i<=num_dv;i++)
			if($('#txtdienvien'+i).is(':checked'))
			{
				dienvien=document.getElementById("txtdienvien"+i).value;
				break;
			}
	}
	else
	{
		var dienvien = new Array();
		k=0;
		for(i=1;i<=num_dv;i++)
		{
			if($('#txtdienvien'+i).is(':checked'))
			{
				
				dienvien[k]=document.getElementById("txtdienvien"+i).value;
				k++;
			}
		}
	}
	
    http.open("post", "libraries/themmoiajax.php", true);
    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8");
    http.onreadystatechange = process_dangphim;
	http.send(	"tp=" +tenphim+ 
				"&tl=" +thoiluong+
				"&gt="+gioithieu+
				"&nhasx="+nhasx+
				"&daodien="+daodien+
				"&quocgia="+quocgia+
				"&chatluong="+chatluong+
				"&chuyenngu="+chuyenngu+
				"&namsx="+namsx+
				"&ngaydang="+ngaydang+
				"&ngaydangtm="+ngaydangtm+
				"&theloai="+theloai+
				"&dienvien="+dienvien+
				"&loaiphim="+loaiphim);
}
function process_dangphim() 
{
    if (http.readyState == 4 && http.status == 200) 
	{
		
		result = http.responseText;
		if(result!=1)
			document.getElementById("thongbao").innerHTML = result;
		else
		{
			alert("Thêm thành công.");
			window.location="admin_dangtapphim.php";
		}
    }
}